package com.dede.baselib;

import android.app.Application;

import com.dede.baselib.state.Empty;
import com.dede.baselib.state.Error;
import com.dede.baselib.state.Loading;
import com.dede.rxbase.config.BaseConfig;
import com.dede.state.Converter;
import com.dede.state.State;
import com.dede.state.component.StateComponent;
import com.dede.state.component.SuccessComponent;

/**
 * @author hsh
 * @date 2018/1/18 14:53.
 * @doc
 */
public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        BaseConfig.init(this)
                .noActionBar()
                .debug(true);

        State.begin()
                .addComponent(new Loading())
                .addComponent(new Empty())
                .addComponent(new Error())
                .converter(new Converter<Integer>() {
                    @Override
                    public Class<? extends StateComponent> map(Integer integer) {
                        switch (integer) {
                            case 0:
                                return Empty.class;
                            case -1:
                                return Error.class;
                            case 2:
                                return Loading.class;
                            case 1:
                            default:
                                return SuccessComponent.class;
                        }
                    }
                })
                .builder();
    }
}
